
<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/favicon.ico">
    <link rel="canonical" href="https://getbootstrap.com/docs/3.4/examples/dashboard/">

    <title>基于Django的气象数据采集和分析</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/examples/dashboard/dashboard.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">基于Django的气象数据采集和分析</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#">欢迎登陆</a></li>
            <li><a href="login.html">退出</a></li>
          </ul>
        </div>
      </div>
    </nav>

    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
          <ul class="nav nav-sidebar">
            <li><a href="crawler.html">数据爬取</a></li>
            <li><a href="user.html">用户管理</a></li>
            <li><a href="city.html">城市分析</a></li>
            <li><a href="meteorology.html">气象分析</a></li>
            <li class="active"><a href="max_temperature.html">最高温度升序排行榜</a></li>
            <li><a href="max_temperature_desc.html">最高温度降序排行榜</a></li>
            <li><a href="min_temperature.html">最低温度升序排行榜</a></li>
            <li><a href="min_temperature_desc.html">最低温度降序排行榜</a></li>
          </ul>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
          <h1 class="page-header">最高温度升序排行榜</h1>
          <!-- 搜索框 -->
          <div class="panel-body">
              <form role="form" id="searchForm" class="form-inline">
                  <div class="form-group"> <input type="text"
                          class="form-control" id="publish_time" name="publish_time" placeholder="请输入日期">
                  </div>
                  <div class="form-group"> <input type="text"
                          class="form-control" id="week" name="week" placeholder="请输入星期">
                  </div>
                  <div class="form-group"> <input type="text"
                          class="form-control" id="weather" name="weather" placeholder="请输入天气状况">
                  </div>
                  <div class="form-group"> <input type="text"
                          class="form-control" id="city__name" name="city__name" placeholder="请输入城市名称">
                  </div>
                  <div class="form-group">
                      <button type="button" id="searchBtn" class="btn btn-default">开始搜索</button>
                  </div>
              </form>
          </div>
          <div id="container" style="height: 500px"></div>
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
    <script>window.jQuery || document.write('<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/js/vendor/jquery.min.js"><\/script>')</script>
    <script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/dist/js/bootstrap.min.js"></script>
    <!-- Just to make our placeholder images work. Don't actually copy the next line! -->
    <script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/js/vendor/holder.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.4/assets/js/ie10-viewport-bug-workaround.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
    <script src="assets/js/table/bootstrap-table.js"></script>
    <script src="assets/js/table/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript">
      var myChart='';
      var dom = document.getElementById("container");
      var xValue = [];
      var yValue = [];
      // 通用初始化模板
      function initEcharts(valueX, valueY){
        myChart = echarts.init(dom);
        var app = {};
        var option;
        option = {
            xAxis: {
                type: 'category',
                data: valueX
            },
            yAxis: {
                type: 'value'
            },
            series: [{
                data: valueY,
                type: 'bar'
            }],
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            }
        };

        if (option && typeof option === 'object') {
            myChart.setOption(option,true);
        }
      }
      // 初始化表格数据
      $(function(){
        $.ajax({
          url: "http://127.0.0.1:8082/api/crawler/get_citydata_by_name_or_year/",
          method: "get",
          dataType: "json",
          data: {
            ordering : 'top_temperature'
          },
          success: function(rs){
            var result = rs.results
            console.log(result)
            for (var i=0; i<15;i++){
              yValue.push(parseInt(result[i].top_temperature))
              xValue.push(result[i].city + " "+ result[i].publish_time)
            }
            initEcharts(xValue, yValue);
          },
        })
      });
      // 搜索
      $("#searchBtn").click(function() {
        var publish_time = $("#publish_time").val();
        var week = $("#week").val();
        var weather = $("#weather").val();
        var city__name = $("#city__name").val();
        $.ajax({
          type: "get",
          url: "http://127.0.0.1:8082/api/crawler/get_citydata_by_name_or_year/",
          cache: false,
          data: {
            publish_time : publish_time,
            week : week,
            weather : weather,
            city__name : city__name,
            ordering : 'top_temperature'
          },
          success : function(res) {
            var result = res.results
            myChart.clear();
            myChart = '';
            yValue = []
            xValue = []
            for (var i=0; i<15;i++){
              yValue.push(parseInt(result[i].top_temperature))
              xValue.push(result[i].city + " "+ result[i].publish_time)
            }
            initEcharts(xValue, yValue);
          }
        });
      });
    </script>
  </body>
</html>
